<template>
  <div class="home-new">
    <HomePanel
      title="新鲜好物"
      subTitle="新鲜出炉 品质靠谱"
    >
      <template #right>
        <XtxMore path="/test" />
      </template>
      <!-- 面板内容 -->
      <div
        ref="target"
        style="position:relative;height:426px"
      >
        <Transition name="fade">
          <ul
            class="goods-list"
            v-if="goods.length"
          >
            <li
              v-for="item in goods"
              :key="item.id"
            >
              <RouterLink to="/" />
              <img :src="item.picture">
              <p class="name ellipsis">{{item.name}}</p>
              <!-- 规范HTML书写，人民币书写请用“&yen” -->
              <p class="price">&yen;{{item.price}}</p>
            </li>
          </ul>
          <HomeSkeleton
            v-else
            bg="#f0f9f4"
          />
        </Transition>
      </div>
    </HomePanel>
  </div>
</template>

<script>
import HomePanel from './home-panel'
import HomeSkeleton from '@/views/home/components/home-skeleton'
import { findNew } from '@/api/home'
import { ref } from 'vue'
import { uselazyData } from '@/hooks/index'
export default {
  name: 'HomeNew',
  components: { HomePanel, HomeSkeleton },
  setup() {
    // 新鲜好物的数据
    // const goods = ref([])
    // const box = ref(null)
    const { target, result } = uselazyData(findNew)
    // findNew().then(data => {
    //   goods.value = data.result
    // })
    // console.log(goods);
    return { goods: result, target }
  }
}
</script>

<style lang="less" scoped>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>